//
//  UIView+layer.m
//  HuoGameBox
//
//  Created by user on 2018/12/26.
//  Copyright © 2018年 huosdk. All rights reserved.
//

#import "UIView+layer.h"
#import "UIColor+String.h"
@implementation UIView (layer)


-(void)corners:(UIRectCorner)coner Andsize:(CGSize)size withBorderColor:(NSString *)color{
    
    UIBezierPath * path = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:coner cornerRadii:size];
    
    CAShapeLayer * shapLayer = [[CAShapeLayer alloc]init];
    
    shapLayer.frame = self.bounds;
    shapLayer.lineWidth = 1.5;
    if (color != nil && ![color  isEqual: @""]) {
        
        shapLayer.strokeColor = [UIColor hexStringColor:color].CGColor;
    }
    //shapLayer.backgroundColor = [UIColor hexStringColor:color].CGColor;
    shapLayer.fillColor = UIColor.clearColor.CGColor;
    shapLayer.path = path.CGPath;
    [self.layer addSublayer:shapLayer];
    
    CAShapeLayer * shapLayer2 = [[CAShapeLayer alloc]init];
    shapLayer2.frame = self.bounds;
    shapLayer2.path = path.CGPath;
    self.layer.mask = shapLayer2;
}

+ (void)cx_gradientViewWithColors:(NSArray *)colors locations:(NSArray<NSNumber *> *)locations startPoint:(CGPoint)startPoint endPoint:(CGPoint)endPoint selfView:(nonnull UIView *)selfView{
    CAGradientLayer *gradientLayer = [CAGradientLayer layer];
    
    NSMutableArray * colorM = [NSMutableArray array];
    for( NSString * colorStr in colors) {
        [colorM addObject:(__bridge id)[UIColor hexStringColor:colorStr].CGColor];
    }
    gradientLayer.colors = [colorM copy];
    gradientLayer.locations = locations;
    gradientLayer.startPoint = startPoint;
    gradientLayer.endPoint = endPoint;
    gradientLayer.frame = selfView.bounds;
    [selfView.layer addSublayer:gradientLayer];
    
}


@end
